package com.swpu.select.controller;

import com.swpu.select.pojo.Course;
import com.swpu.select.service.CourseService;
import com.swpu.select.service.impl.CourseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import com.swpu.select.pojo.Course;
import com.swpu.select.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CourseController {

    @Autowired
    private CourseService courseService;
    // 添加课程
    @PostMapping("/addCourse")
    public Integer addCourse(@RequestBody Course course) {
        return courseService.addCourse(course);
    }

    // 更新课程
    @PostMapping("/updateCourse")
    public Integer updateCourse(@RequestBody Course course) {
        return courseService.updateCourse(course);
    }

    // 删除课程
    @PostMapping("/deleteCourse/{courseId}")
    public Integer deleteCourse(@PathVariable String courseId) {
        return courseService.deleteCourse(courseId);
    }

    // 根据ID查询课程
    @PostMapping("/getCourse/{courseId}")
    public Course getCourseById(@PathVariable String courseId) {
        return courseService.getCourseById(courseId);
    }

    // 获取所有课程
    @PostMapping("/allCourse")
    public List<Course> getAllCourses() {
        return courseService.getAllCourses();
    }

    // 根据院系查询课程
    @GetMapping("/department/{department}")
    public List<Course> getCoursesByDepartment(@PathVariable String department) {
        return courseService.getCoursesByDepartment(department);
    }

    // 根据专业查询课程
    @GetMapping("/major")
    public List<Course> getCoursesByMajor(@RequestParam  String major) {
        return courseService.getCoursesByMajor(major);
    }

    @GetMapping("/teacher")
    public List<Course> getCoursesByTeacher(@RequestParam  String name) {
        return courseService.getCoursesByTeacher(name);
    }
    // 根据学分查询课程
    @GetMapping("/credit")
    public List<Course> getCoursesByCredit(@RequestParam int credit) {
        return courseService.getCoursesByCredit(credit);
    }

    // 获取课程总数
    @PostMapping("/count")
    public int getCourseCount() {
        return courseService.getCourseCount();
    }

    // 获取平均学分
    @PostMapping("/avgCredit")
    public double getAverageCredit() {
        return courseService.getAverageCredit();
    }
}